<template>
  <div id="listNavChange">
    <el-collapse v-model="open">
      <el-collapse-item title="内容" name="1">
        <div class="content-bg" v-for="(v,i) in styles.imgUrl" :key="i">
          <ul class="content-list">
            <li>
              <span>左侧图标：</span>
              <div>
                <upLoadImage :v="v" :height="50"></upLoadImage>
              </div>
            </li>
            <li>
              <span>左侧文字：</span>
              <div>
                <el-input
                  type="text"
                  placeholder="请输入内容"
                  v-model="v.leftWord"
                  maxlength="10"
                  show-word-limit
                />
              </div>
            </li>
            <li>
              <span>右侧文字：</span>
              <div>
                <el-input
                  type="text"
                  placeholder="请输入内容"
                  v-model="v.rightWord"
                  maxlength="10"
                  show-word-limit
                />
              </div>
            </li>
            <li>
              <span>链接：</span>
              <div>
                <upLoadUrl :v="v" :width="360"></upLoadUrl>
              </div>
            </li>
          </ul>
          <i @click="deletePic(i)" class="el-icon-error delete"></i>
        </div>
        <el-button @click="addList" size="small" style="width:100%" plain>
          <i class="el-icon-plus"></i>
          <span>添加</span>
        </el-button>
      </el-collapse-item>
    </el-collapse>
    <el-collapse v-model="open2">
      <el-collapse-item title="内容样式" name="2">
        <ul class="content-list">
          <li>
            <span>左侧文字：</span>
            <div>
              <colorSetting v-model="styles.leftColor" :originColor="styles.leftColor" initColor="#212121"></colorSetting>
            </div>
          </li>
          <li>
            <span>右侧文字：</span>
            <div>
              <colorSetting v-model="styles.rightColor" :originColor="styles.rightColor" initColor="#969696"></colorSetting>
            </div>
          </li>
          <li>
            <span>右侧图标：</span>
            <div>
              <upLoadImage :v="styles" :height="50"></upLoadImage>
            </div>
          </li>
          <li>
            <span>上间距：</span>
            <div>
              <edgeSetting v-model="styles.marginTop" unit="px" :max="50" :init="Number(styles.marginTop)"></edgeSetting>
            </div>
          </li>
          <li>
            <span>下间距：</span>
            <div>
              <edgeSetting v-model="styles.marginBottom" unit="px" :max="50" :init="Number(styles.marginBottom)"></edgeSetting>
            </div>
          </li>
          <li>
            <span>左右间距：</span>
            <div>
              <edgeSetting v-model="styles.marginLR" unit="px" :max="50" :init="Number(styles.marginLR)"></edgeSetting>
            </div>
          </li>
        </ul>
        </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import upLoadImage from "../../comm/upLoadImage";
import colorSetting from "../../comm/colorSetting";
import upLoadUrl from "../../comm/uploadUrl";
import edgeSetting from "../../comm/edgeSetting";
export default {
  name: "listNavChange",
  data() {
    return {
      open: "1",
      open2:"2"
    };
  },
  computed: {
    ...mapState(["list", "currentId", "currentName"]),
    styles() {
      return this.list[this.currentId].styles;
    },
  },
  components: {
    colorSetting,
    upLoadImage,
    upLoadUrl,
    edgeSetting
  },
  methods: {
    addList() {
      if (this.num != undefined) {
        if (this.styles.imgUrl.length >= 4) {
          this.$message.error("此元素最多允许添加四个！");
          return false;
        }
      }
      this.styles.imgUrl.push({
        img: "",
        leftWord: "文字",
        rightWord: "查看",
        url: "",
      });
    },
    deletePic(i) {
      if (this.styles.imgUrl.length == 1) {
        return false;
      }
      this.styles.imgUrl.splice(i, 1);
      console.log(this.list);
    },
  },
};
</script>


<style lang='less' scoped>
@import url("../../../assets/css/base.less");
.content-bg:hover {
  .delete {
    display: block;
  }
}
.content-bg {
  background-color: #f7f7f7;
  padding: 10px 10px 20px;
  margin-bottom: 10px;
  position: relative;
  .delete {
    position: absolute;
    right: 0;
    top: 0;
    font-size: 20px;
    display: none;
  }
}
</style>
